import java.util.Arrays;
import java.util.Scanner;

public class C {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ty[] t = new ty[n + 10];
		for(int i = 1; i <= n; i ++ ) {
			t[i] = new ty();
			t[i].a = sc.nextInt();
			t[i].b = sc.nextInt();
		}
		Arrays.sort(t, 1, n + 1);
		long ret = 0;
		for(int i = 1; i <= n - 1; i ++ ) {
			ret += t[i].a;
		}
		ret += t[n].b;
		System.out.print(ret);
	}
}

class ty implements Comparable<ty>{
	int a;
	int b;
	@Override
	public int compareTo(ty o) {
		return (this.b - this.a) -(o.b - o.a);
	}
}